<template>
	<div>
		<Header></Header>
		<el-container>
		  <el-main>
		    <el-row :gutter="20">
		
		      <el-col :span="24">
		        <div class="grid-content bg-purple">
		          <el-card class="news-content">
		            <div class="news-head">
		              <img class="news-post" src="../assets/logo.png" width="40px" height="40px" />
		              <span class="news-author">与时网</span>
		              <span class="news-time"><i class="el-icon-date"></i> 发布时间: {{news.created}}</span>
		              <el-button class="concern" type="danger"><i class="el-icon-plus"></i> 关注</el-button>
		              <el-divider></el-divider>
		            </div>
					
		            <div class="news-main">
						
						 <div class="mnews">
						   <h2> {{ news.title }}</h2>
						   <el-link icon="el-icon-edit" v-if="ownNews">
							 <router-link :to="{name: 'newsedit', params: {newsId: news.id}}" >
							 编辑
							 </router-link>
						   </el-link>
						   <el-divider></el-divider>
						   <div class="markdown-body" v-html="news.content"></div>
						 
						 </div>
					 
		            </div>
					
		          </el-card>
		
		        </div>
		      </el-col>
		

		
		    </el-row>
		  </el-main>
		
		</el-container>
		<Footer></Footer>
	</div>
</template>

<script>
	import 'github-markdown-css'
	import Header from "../components/Header";
	import Footer from "@/components/Footer"
	
	export default{
		name:'newsdetail',
		components:{Header,Footer},
		data() {
		  return {
		    value:'',
		    activeName: 'first',
		    text: '',
		    textarea: '',
			news: {
			  id: "",
			  title: "",
			  content: "",
			  created:""
			},
			newss:{},
			ownNews: false
		  }
		},
		methods: {
			
		  handleClick(tab, event) {
		    console.log(tab, event);
		  }
		},
		created() {
		  const newsId = this.$route.params.newsId
		  console.log(newsId)
		  const _this = this
		  this.$axios.get('/news/' + newsId).then(res => {
		    const news = res.data.data
		    _this.news.id = news.id
		    _this.news.title = news.title
			 _this.news.created = news.created
		
		    var MardownIt = require("markdown-it")
		    var md = new MardownIt()
		
		    var result = md.render(news.content)
		    _this.news.content = result
		    _this.ownNews = (news.userId === _this.$store.getters.getUser.id)
		  })
		}
	}
</script>

<style>
	.news-content {
	    width: auto;
	  }
	  .news-post{
	    border: gray 3px solid;
	    border-radius: 50%;
	  }
	  .news-head{
	   /* background-color: #42B983; */
	  }
	  .news-author{
	    margin-left: 5px;
	    color: gray;
	    font-size: 20px;
	  }
	  .news-time{
	    margin-left: 10px;
	    color: gray;
	    font-size: 10px;
	  }
	  /* 关注按钮 */
	  .concern{
	    width: 90px;
	    margin-top: 10px;
	    float: right;
	  }
	
	.news-main{
	
	}
	.news-text{
	 /* background-color: #545C64; */
	  color:gray;
	  word-wrap: break-word;
	  margin-top: 10px;
	  text-indent: 2em;
	}
	  .news-r {
	    margin-bottom: 30px;
	    width: auto;
	  }
	  .news-padding{
	    margin-bottom: 10px;
	  }
	  
	  .mnews {
	    width: 100%;
	    min-height: 700px;
	    padding: 20px 15px;
	  }
</style>
